<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once 'Classes/Model/PDOModel.php';
require_once 'Classes/Sub_Family.php';


class Sub_FamilyModel extends PDOModel implements Singleton
{
    
     private static $instance;
     
     public function getInstance(){
        if (!isset(self::$instance)) {
            $c = __CLASS__;
            self::$instance = new $c;
        }

        return self::$instance;
     }
     
     protected function __construct() {
        parent::__construct();
    }
     
     public function __clone() {
         throw new Exception("You may not try to clone this object");
     }
 
    
    public function ListAllSub_Families(){       
         $sql = "SELECT ID,Name, Optional_1, Optional_2, Optional_3, Optional_4, Optional_5, Optional_6 FROM Sub_Families ORDER BY ID DESC";       
                 
         $dbData= $this->PDORequest($sql, array());
         $subFamilyArray = array();
         foreach ($dbData as $key => $value) {
             array_push($subFamilyArray, new Sub_Family($value));
         }
         $subFamilyArray = array();
         foreach ($dbData as $key => $value) {
             array_push($subFamilyArray, new Sub_Family($value));
         }
         return $subFamilyArray;
    }
    
    public function ListSub_Families($Family){       
         $sql = "SELECT * FROM`Sub_Families` WHERE FamilyID = ? ORDER BY ID DESC";       
                 
         $dbData =  $this->PDORequest($sql,array($Family->getId())); 
         $subFamilyArray = array();
         foreach ($dbData as $key => $value) {
             array_push($subFamilyArray, new Sub_Family($value));
         }
         return $subFamilyArray;

    }
    
    public function ListSub_FamiliesById($id){       
         $sql = "SELECT * FROM `Sub_Families` WHERE ID = ? ORDER BY ID DESC";       
         
         $dbData =  $this->PDORequest($sql,array($id)); 
         return $dbData[0];

    }
    
    public function ListSub_FamiliesByFamilyId($id){       
         $sql = "SELECT * FROM Sub_Families WHERE FamilyID = ? ORDER BY ID DESC";       
                 
         $dbData = $this->PDORequest($sql,array($id));
         $subFamilyArray = array();
         foreach ($dbData as $key => $value) {
             array_push($subFamilyArray, new Sub_Family($value));
         }
         return $subFamilyArray;
    }
    
    public function AddSub_Family($Name, $Optional_1, $Optional_2, $Optional_3, $Optional_4, $Optional_5, $Optional_6, $FamilyID){
         $sql = "INSERT INTO Sub_Families (Name, Optional_1, Optional_2, Optional_3, Optional_4, Optional_5, Optional_6, FamilyID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";

         $dbData = $this->PDORequest($sql,array($Name, $Optional_1, $Optional_2, $Optional_3, $Optional_4, $Optional_5, $Optional_6, $FamilyID));
    }
    
    public function UpdateSub_FamilyNamed($Name, $Optional_1, $Optional_2, $Optional_3, $Optional_4, $Optional_5, $Optional_6){
         $sql = "UPDATE Sub_Families SET Name=?, Optional_1=?, Optional_2=?, Optional_3=?, Optional_4=?, Optional_5=?, Optional_6=? WHERE Sub_Families.Name =?";
         $this->PDORequest($sql,array($Name, $Optional_1, $Optional_2, $Optional_3, $Optional_4, $Optional_5, $Optional_6, $Name));
    }
    
    public function UpdateSub_FamilyById($id,$Name, $Optional_1, $Optional_2, $Optional_3, $Optional_4, $Optional_5, $Optional_6){
         $sql = "UPDATE Sub_Families SET Name=?, Optional_1=?, Optional_2=?, Optional_3=?, Optional_4=?, Optional_5=?, Optional_6=? WHERE ID =?";
         $this->PDORequest($sql,array($Name, $Optional_1, $Optional_2, $Optional_3, $Optional_4, $Optional_5, $Optional_6, $id));
    }
    
    public function DeleteSub_FamilyNamed($Name){
         $sql = "DELETE FROM Sub_Families WHERE Name = ?";
         $this->PDORequest($sql,array($Name));
    }
    
     public function DeleteSub_FamilyById($id){
         $sql = "DELETE FROM Sub_Families WHERE ID = ?";
         $this->PDORequest($sql,array($id));
    }
    
}

?>
